var jsonList = {};
jsonList.state = 4;
var page = 1;
var rows = 10;
$(function () {
    //获取文章列表详情
    $(document).on("click", ".arc_open", function () {
        var id = $(this).attr("arid");
        console.log(id);
        window.location.href = "./fabu_wz.html?id=" + id;
    })
    //撤销发布
    $(".c_xiao").on("click", function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要撤销发布吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/release/aticle/cancel?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        console.log(res, 333)
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('撤销发布失败');
                        }
                    }
                })
            })
        } else {
            zeroModal.alert('请选择至少一条短评撤销发布');
        }
    })
    //获取频道列表
    var jsonl = {};
    var result = JSON.stringify(jsonl);
    $.ajax({
        url: baseNews + "/api/data/channel/list?page=1&rows=200",
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res);
            if (res.code == 0) {
                var obj = $(".pindaolist");
                $(res.data.list).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.cname + "</option>");
                })
            }
        }
    })
})
getList();
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/common/article/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".yfb_list").empty();
                $(list).each(function (index, key) {
                    var state = key.sstate;//zhuanti的状态
                     var state1 = key.state;//zhuanti的状态
                    var newState = "";
                    var newState1 = "";
                    if (state == 0) {
                        newState = "";
                    }
                    if (state == 1) {
                        newState = "待审核";
                    }
                    if (state == 2) {
                        newState = "待发布";
                    }
                    if (state == 3) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "有更新";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    //
                    if (state1 == 0) {
                        newState1 = "新建";
                    }
                    if (state1 == 1) {
                        newState1 = "已经改";
                    }
                    if (state1 == 2) {
                        newState1 = "待审核";
                    }
                    if (state1 == 3) {
                        newState1 = "待发布";
                    }
                    if (state1 == 4) {
                        newState1 = "已发布";
                    }
                    if (state1 == 10) {
                        newState1 = "有更新";
                    }
                    if (state1 == -1) {
                        newState1 = "审核失败";
                    }
                    if (state1 == -2) {
                        newState1 = "撤销发布";
                    }
                    html +=`<tr>
                                 <td><input  class="arc_isc"  type="checkbox"  oid="${key.id}"/></td> 
                                 <td>${key.id}</td>
                                 <td>${key.title}</td> 
                                 <td>${newState1}</td>
                                 <td>${key.sid}</td> 
                                 <td>${key.stitle}</td>
                                 <td>${newState}</td> 
                                 <td>13</td>
                                 <td></td>
                            </tr>`;
                })
                $(".yfb_list").append(html);
            }
        }

    })
    //分页
    
    
}
$(function (){
    //搜索
    $(".in_ztai").change(function () {
        jsonList.sstate = $(this).val();
    })
    $(".pindaolist").change(function () {
        jsonList.cid = $(this).val();
    })
    $(".in_sou").click(function () {
        var wz_name = $(".wz_name").val();//文章名称
        var zt_id = $(".zt_id").val();//专题id
        var zt_name = $('.zt_name').val();//专题名称
        if (wz_name != "") {
            jsonList.title = wz_name
        }
        if (zt_id != "") {
            jsonList.sid = zt_id
        }
        if (zt_name != "") {
            jsonList.stitle = zt_name
        }
        console.log(jsonList,333333)
        getList();
    })
})
